package com.senven.shoppingcar.controller;

import com.senven.common.entity.Branch;
import com.senven.common.entity.ShoppingTrolley;
import com.senven.shoppingcar.feign.BranchFeign;
import com.senven.shoppingcar.service.IShoppingTrolleyService;
import com.senven.shoppingcar.vo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 周世玉
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/shoppingcar/shoppingTrolley")
public class ShoppingTrolleyController {

    @Autowired
    private IShoppingTrolleyService trolleyService;


    //查询店铺的信息
    @GetMapping("/findBranName")
    public CommonResult findBranName(Object token){
        return trolleyService.findBranchName(token);
    }

    //查询当前店铺的菜品销量
    @PostMapping("/dishesSales")
    public CommonResult dishesSales(@RequestBody Map map){
        return trolleyService.findDishesSales(map);
    }

    //查询每个店的销量
    @PostMapping("/shopSales")
    public CommonResult shopSalesAll(String start,String end){
        return trolleyService.shopSalesAll(start,end);
    }

    //逻辑删除
    @PostMapping("/deleteIsDeleted")
    public CommonResult delete(@RequestBody List<Integer> stIds){
        System.out.println(stIds);
        return trolleyService.deleteIsDeleted(stIds);
    }

    //查询购物车信息
    @GetMapping("/findAll")
    public CommonResult findAll(String userid){
        return trolleyService.selectAll(userid);
    }

    //增加商品的数量
    @GetMapping("/addNum")
    public CommonResult addNum(Integer gid,Integer bid){
        return trolleyService.updateAddNum(gid,bid);
    }

    //减少商品的数量
    @GetMapping("/reduceNum")
    public CommonResult reduceNum(Integer gid,Integer bid){
        return trolleyService.updateReduceNum(gid,bid);
    }

}
